{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Accessing Ensembl with BioServices\n",
    "\n",
    "This notebook illustrates some of the functionalities of the ensembl service accessible from BioServices ensembl module. \n",
    "\n",
    "- [Introductory example](#introduction)\n",
    "- [Archive](#archive)\n",
    "- [Comparative genomics](#comparative)\n",
    "- [Cross References](#reference)\n",
    "- [Information](#information)\n",
    "- [Lookup](#lookup)\n",
    "- [Mappingp](#mapping)\n",
    "- [Ontology and Taxonomy](#ontology)\n",
    "- [Overlap](]overlap)\n",
    "- [Regulation](#regulation)\n",
    "- [Sequences](#sequences)\n",
    "- [Variation](#variation)\n",
    "\n",
    " **References**   : http://rest.ensembl.org/ \n",
    "             "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'bioservices.ensembl' from '/home/cokelaer/Work/github/bioservices/src/bioservices/ensembl.pyc'>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from bioservices import ensembl\n",
    "# for debugigng\n",
    "reload(ensembl)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "e = ensembl.Ensembl()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "e.TIMEOUT = 60"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## <a name=\"introduction\"></a> Introductory example"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Most of the methods takes one or 2 compulsary arguments\n",
    "- an argument that is not part of the Ensembl API is **frmt**. It can be set to one of the Ensemble output format that is:\n",
    "    - json\n",
    "    - jsonp\n",
    "    - xml\n",
    "    - phyloxml\n",
    "- By default, output is in json format, which is transformed into a Python dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'assembly': u'GRCh38',\n",
       " u'id': u'ENSG00000157764',\n",
       " u'is_current': u'1',\n",
       " u'latest': u'ENSG00000157764.12',\n",
       " u'peptide': None,\n",
       " u'possible_replacement': [],\n",
       " u'release': u'83',\n",
       " u'type': u'Gene',\n",
       " u'version': u'12'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_archive('ENSG00000157764')\n",
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{u'peptide': None, u'possible_replacement': [], u'version': u'12', u'is_current': u'1', u'release': u'83', u'assembly': u'GRCh38', u'type': u'Gene', u'id': u'ENSG00000157764', u'latest': u'ENSG00000157764.12'}\n"
     ]
    }
   ],
   "source": [
    "# you can change the format to phyloxml (even though it does not make sense in this context)\n",
    "print(e.get_archive('ENSG00000157764', frmt='json'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
      "\n",
      "<phyloxml xsi:schemaLocation=\"http://www.phyloxml.org http:/\n"
     ]
    }
   ],
   "source": [
    "res = e.get_genetree_by_member_id('ENSG00000157764', frmt='json', nh_format='phylip')\n",
    "print(res[0:100])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Here, the input frmt (json) is changed since nh_format can be only in phyloxml format\n",
    " So example requires a parameter called nh_format that may overwrite the value of the argument **frmt** even if provided. \n",
    " An example is shown later with the nh_format set to phylib, which is an xml format. If the user set frmt to json, it does \n",
    " make sense so that arguments is ignored."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(500,\n",
       " {u'assembly_name': u'GRCh38',\n",
       "  u'coord_system': u'chromosome',\n",
       "  u'end': 140924703,\n",
       "  u'gap': 0,\n",
       "  u'rank': 0,\n",
       "  u'seq_region_name': u'7',\n",
       "  u'start': 140924566,\n",
       "  u'strand': -1})"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# If your identifier is incorrect, you will get a 500 error code returned (most probably)\n",
    "wrong = e.get_map_cds_to_region('ENST0000288602', '1..1000')\n",
    "good = e.get_map_cds_to_region('ENST00000288602', '1..1000')\n",
    "wrong, good['mappings'][0]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## <a name=\"archive\"></a> Archive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'assembly': u'GRCh38',\n",
       " u'id': u'ENSG00000157764',\n",
       " u'is_current': u'1',\n",
       " u'latest': u'ENSG00000157764.12',\n",
       " u'peptide': None,\n",
       " u'possible_replacement': [],\n",
       " u'release': u'83',\n",
       " u'type': u'Gene',\n",
       " u'version': u'12'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get archived sequence given an identifer\n",
    "e.get_archive('ENSG00000157764')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## <a name=\"comparitive\"></a> Comparative genomics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Gene tree by identifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(u'ENSGT00390000003602', [u'type', u'tree', u'rooted', u'id'])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_genetree_by_id('ENSGT00390000003602', nh_format='simple')\n",
    "res['id'], res.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
      "\n",
      "<phyloxml xsi:schemaLocation=\"http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"ht\n"
     ]
    }
   ],
   "source": [
    "res = e.get_genetree_by_id('ENSGT00390000003602', frmt='phyloxml')\n",
    "print(res[0:200])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Retrieve genetree by member id and returns a phylip structure\n",
    "This takes a few seconds and output xml is large`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Here, the input frmt (json) is changed since nh_format can be only in phyloxml format\n",
    "res = e.get_genetree_by_member_id('ENSG00000157764', frmt='json', nh_format='phylip')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2204716"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
      "\n",
      "<phyloxml xsi:schemaLocation=\"http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.phyloxml.org\">\n",
      "  <phylogeny rooted=\"true\" type=\"gene tree\">\n",
      "    <clade branch_length=\"0\">\n",
      "      <confidence type=\"duplication_confidence_score\">1.0000</confidence>\n",
      "      <taxonomy>\n",
      "        <id>33213</id>\n",
      "        <scientific_name>Bilateria</scientific_name>\n",
      "      </taxonomy>\n",
      "      <events>\n",
      " \n"
     ]
    }
   ],
   "source": [
    "print(res[0:500])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "res = e.get_genetree_by_member_symbol('human', 'BRCA2', nh_format='simple')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(((((((ENSTRUP00000015030:0.074146,ENSTNIP00000002435:0.10955):0.221789,ENSGACP00000015199:0.154409):0.017205,((ENSXMAP00000006983:0.039547,ENSPFOP00000001575:0.039869):0.385538,ENSONIP00000006940:0.3\n"
     ]
    }
   ],
   "source": [
    "print(res[0:200])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## <a name=\"reference\"></a> Cross references"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "get_xrefs_by_id() takes at least 2 arguments (1 given)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-13-a939ac6ace55>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_xrefs_by_id\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: get_xrefs_by_id() takes at least 2 arguments (1 given)"
     ]
    }
   ],
   "source": [
    "res = e.get_xrefs_by_id()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## <a name=\"information\"></a> Information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e.get_info_ping()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'release': u'4.3'}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e.get_info_rest()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'release': 82}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_info_software()\n",
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[u'saccharomyces_cerevisiae',\n",
       " u'ciona_savignyi',\n",
       " u'myotis_lucifugus',\n",
       " u'taeniopygia_guttata',\n",
       " u'sorex_araneus',\n",
       " u'otolemur_garnettii',\n",
       " u'macropus_eugenii',\n",
       " u'erinaceus_europaeus',\n",
       " u'anolis_carolinensis',\n",
       " u'gadus_morhua',\n",
       " u'dasypus_novemcinctus',\n",
       " u'chlorocebus_sabaeus',\n",
       " u'tursiops_truncatus',\n",
       " u'mus_musculus',\n",
       " u'bos_taurus',\n",
       " u'monodelphis_domestica',\n",
       " u'choloepus_hoffmanni',\n",
       " u'sus_scrofa',\n",
       " u'rattus_norvegicus',\n",
       " u'caenorhabditis_elegans',\n",
       " u'pteropus_vampyrus',\n",
       " u'microcebus_murinus',\n",
       " u'sarcophilus_harrisii',\n",
       " u'ovis_aries',\n",
       " u'papio_anubis',\n",
       " u'pelodiscus_sinensis',\n",
       " u'equus_caballus',\n",
       " u'xiphophorus_maculatus',\n",
       " u'macaca_mulatta',\n",
       " u'astyanax_mexicanus',\n",
       " u'latimeria_chalumnae',\n",
       " u'ficedula_albicollis',\n",
       " u'gasterosteus_aculeatus',\n",
       " u'gorilla_gorilla',\n",
       " u'oryctolagus_cuniculus',\n",
       " u'oreochromis_niloticus',\n",
       " u'echinops_telfairi',\n",
       " u'nomascus_leucogenys',\n",
       " u'homo_sapiens',\n",
       " u'dipodomys_ordii',\n",
       " u'lepisosteus_oculatus',\n",
       " u'anas_platyrhynchos',\n",
       " u'canis_familiaris',\n",
       " u'callithrix_jacchus',\n",
       " u'pongo_abelii',\n",
       " u'ornithorhynchus_anatinus',\n",
       " u'tetraodon_nigroviridis',\n",
       " u'mustela_putorius_furo',\n",
       " u'tarsius_syrichta',\n",
       " u'vicugna_pacos',\n",
       " u'meleagris_gallopavo',\n",
       " u'xenopus_tropicalis',\n",
       " u'ictidomys_tridecemlineatus',\n",
       " u'cavia_porcellus',\n",
       " u'takifugu_rubripes',\n",
       " u'ochotona_princeps',\n",
       " u'pan_troglodytes',\n",
       " u'petromyzon_marinus',\n",
       " u'ailuropoda_melanoleuca',\n",
       " u'felis_catus',\n",
       " u'procavia_capensis',\n",
       " u'oryzias_latipes',\n",
       " u'danio_rerio',\n",
       " u'gallus_gallus',\n",
       " u'tupaia_belangeri',\n",
       " u'ciona_intestinalis',\n",
       " u'loxodonta_africana',\n",
       " u'poecilia_formosa',\n",
       " u'drosophila_melanogaster']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_info_species()\n",
    "[x['name'] for x in res['species']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sequence"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Get a sequence"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CGCCTCCCTTCCCCCTCCCCGCCCGACAGCGGCCGCTCGGGCCCCGGCTCTCGGTTATAA\n"
     ]
    }
   ],
   "source": [
    "sequence = e.get_sequence_by_id('ENSG00000157764', frmt='text')\n",
    "print(sequence[0:60])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Variation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "get_variation_by_id() takes at least 3 arguments (1 given)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-14-bbc10863b50f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_variation_by_id\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: get_variation_by_id() takes at least 3 arguments (1 given)"
     ]
    }
   ],
   "source": [
    "e.get_variation_by_id"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Lookup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[u'assembly_name',\n",
       " u'display_name',\n",
       " u'description',\n",
       " u'seq_region_name',\n",
       " u'logic_name',\n",
       " u'object_type',\n",
       " u'start',\n",
       " u'id',\n",
       " u'source',\n",
       " u'db_type',\n",
       " u'version',\n",
       " u'biotype',\n",
       " u'end',\n",
       " u'Transcript',\n",
       " u'species',\n",
       " u'strand']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_lookup_by_id('ENSG00000157764', expand=True)\n",
    "res.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'assembly_name': u'GRCh38',\n",
       " u'biotype': u'protein_coding',\n",
       " u'db_type': u'core',\n",
       " u'description': u'B-Raf proto-oncogene, serine/threonine kinase [Source:HGNC Symbol;Acc:HGNC:1097]',\n",
       " u'display_name': u'BRAF',\n",
       " u'end': 140924764,\n",
       " u'id': u'ENSG00000157764',\n",
       " u'logic_name': u'ensembl_havana_gene',\n",
       " u'object_type': u'Gene',\n",
       " u'seq_region_name': u'7',\n",
       " u'source': u'ensembl_havana',\n",
       " u'species': u'homo_sapiens',\n",
       " u'start': 140719327,\n",
       " u'strand': -1,\n",
       " u'version': 12}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.post_lookup_by_id([\"ENSG00000157764\", \"ENSG00000248378\" ], expand=0)\n",
    "res['ENSG00000157764']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_lookup_by_symbol('homo_sapiens', 'BRCA2', expand=True)\n",
    "len(res['Transcript'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "easydev tolist deprecated since 0.8.0. use to_list() instead\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.post_lookup_by_symbol('human', [\"BRCA2\", \"BRAF\" ], expand=True)\n",
    "len(res['BRCA2']['Transcript'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Mapping"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\tDescription\n",
    "- Convert from cDNA coordinates to genomic coordinates. Output reflects forward orientation coordinates as returned from the Ensembl API.\n",
    "- GET map/cds/:id/:region \tConvert from CDS coordinates to genomic coordinates. Output reflects forward orientation coordinates as returned from the Ensembl API.\n",
    "- GET map/:species/:asm_one/:region/:asm_two \tConvert the co-ordinates of one assembly to another\n",
    "- GET map/translation/:id/:region \tConvert from protein (translation) coordinates to genomic coordinates. Output reflects forward orientation coordinates as returned from the Ensembl "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'mappings': [{u'mapped': {u'assembly': u'GRCh38',\n",
       "    u'coord_system': u'chromosome',\n",
       "    u'end': 1039365,\n",
       "    u'seq_region_name': u'X',\n",
       "    u'start': 1039265,\n",
       "    u'strand': 1},\n",
       "   u'original': {u'assembly': u'GRCh37',\n",
       "    u'coord_system': u'chromosome',\n",
       "    u'end': 1000100,\n",
       "    u'seq_region_name': u'X',\n",
       "    u'start': 1000000,\n",
       "    u'strand': 1}}]}"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the commented statement does not work\n",
    "# res = e.get_map_assembly_one_to_two('GRCh37', 'NCBI36', region='X:10000000..1000100:1', species='human')\n",
    "res = e.get_map_assembly_one_to_two('GRCh37', 'GRCh38', region='X:1000000..1000100:1')\n",
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'assembly_name': u'GRCh38',\n",
       " u'coord_system': u'chromosome',\n",
       " u'end': 140834815,\n",
       " u'gap': 0,\n",
       " u'rank': 0,\n",
       " u'seq_region_name': u'7',\n",
       " u'start': 140834609,\n",
       " u'strand': -1}"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_map_translation_to_region('ENSP00000288602', '100..300')\n",
    "res['mappings'][0]  # bioservices API may change to res[0] to simpify the output ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'assembly_name': u'GRCh38',\n",
       " u'coord_system': u'chromosome',\n",
       " u'end': 140924703,\n",
       " u'gap': 0,\n",
       " u'rank': 0,\n",
       " u'seq_region_name': u'7',\n",
       " u'start': 140924566,\n",
       " u'strand': -1}"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_map_cds_to_region('ENST00000288602', '1..1000')\n",
    "res['mappings'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'assembly_name': u'GRCh38',\n",
       " u'coord_system': u'chromosome',\n",
       " u'end': 140924665,\n",
       " u'gap': 0,\n",
       " u'rank': 0,\n",
       " u'seq_region_name': u'7',\n",
       " u'start': 140924566,\n",
       " u'strand': -1}"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = e.get_map_cdna_to_region('ENST00000288602', '100..300')\n",
    "res['mappings'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
